package com.travel.modules.asset.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.travel.commons.utils.Constant;
import com.travel.commons.utils.PageUtils;
import com.travel.commons.utils.R;
import com.travel.modules.asset.dto.ScenicAreaQueryDTO;
import com.travel.modules.asset.entity.ScenicArea;
import com.travel.modules.asset.service.ScenicAreaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/static/scenicarea")
public class ScenicAreaController {
    @Resource
    private ScenicAreaService scenicAreaService;

    /**
     * 获取所有符合条件的景点信息
     * @param param : keyword - 关键词
     * @return 符合条件的景点分页
     */
    @RequestMapping("/list")
    public R list(@RequestBody Map<String, Object> param) {
        Integer page = (Integer) param.get("page");
        Integer limit = (Integer) param.get("limit");
        if (page == null || limit == null) {
            return R.error("缺少分页参数");
        }
        
        String keyword = (String) param.get("keyword");
        List<ScenicArea> list = scenicAreaService.ftQueryAreas(StringUtils.isBlank(keyword) ? null : keyword.split(" "));
        return R.ok().put("page", PageUtils.getPage(list, limit, page));
    }

    /**
     * 查询景点的详情信息
     * @param form scenicId - 景点编号
     * @return 景点信息
     */
    @RequestMapping("/info")
    public R info(@RequestBody ScenicArea form) {
        String areaId = form.getAreaId();
        ScenicArea area = scenicAreaService.getOne(new QueryWrapper<ScenicArea>().eq("area_id", areaId));
        area.setHot(area.getHot() + 1);
        scenicAreaService.updateById(area);
        return R.ok().put("page", area);
    }
}
